/*
 *      process_list.h
 *
 *      Copyright 2009 AzureSky <AzureSky.fedora@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#ifndef PROCESS_LIST_H_
#define PROCESS_LIST_H_

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <map>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <unistd.h>
#include <ctime>
#include <sstream>

class process_list {
public:
	process_list();
	virtual ~process_list();

	void read();
	void refresh();
	bool is_end();
	void start();
	bool next();
	int get_pid();
	long get_nice();
	long get_thread_count();

private:
	typedef struct _proc_link{
		std::string name;
		char state;
		int uid;
		long nice;
		long num_threads;
	}proc_link;

	typedef proc_link* proc_link_ptr;
	typedef std::map<int,proc_link_ptr> PROCESS_LIST;

	PROCESS_LIST m_process_list;
	PROCESS_LIST::iterator m_proc_list_it;

	void clear_all();
	bool is_pid(char* pid);
	void add_proc(char* pid);
};

typedef process_list* process_list_ptr;

#endif /* PROCESS_LIST_H_ */
